package com.example.shopping_web_back.mapper;

import com.example.shopping_web_back.pojo.Goods;
import org.apache.ibatis.annotations.*;

import java.util.List;

//主要用于定义商品的与数据库有关的操作
@Mapper
public interface GoodsMapper {

    @Select("select * from shoppingweb.goods_information")
    List<Goods> getAllGoodsData();

    @Select("select * from shoppingweb.goods_information where id = #{id}")
    Goods getGoodsData(String id);

    @Select("select * from shoppingweb.goods_information where business=#{business} and title=#{title}")
    Goods getGoodsDataByBusiness(String business, String title);

    @Insert("insert into shoppingweb.goods_information(title, price, province, area, image, business, salesnum, category)"
             + "value(#{title}, #{price}, #{province}, #{area}, #{image}, #{business}, 0, #{category})")
    void insertGoods(Goods goods);

    @Delete("delete from shoppingweb.goods_information where title=#{title} and business=#{business}")
    void deleteGoods(String title, String business);

    @Update("update shoppingweb.goods_information set title=#{newGoods.title}, price=#{newGoods.price}, province=#{newGoods.province}, area=#{newGoods.area}, salesnum=#{newGoods.salesNum}, image=#{newGoods.image}, category=#{newGoods.category} where business=#{newGoods.business} and title=#{oldTitle}")
    void updateGoods(String oldTitle, Goods newGoods);

    List<Goods> list(String businessName, String category);
}
